﻿<DemoContainer>
    <ApexChart TItem="Order"
               Title="Order Gross Value" Options=options>

        <ApexPointSeries TItem="Order"
                         Items="Orders"
                         Name="Gross Value"
                         SeriesType="SeriesType.Pie"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.GrossValue))"
                         OrderByDescending="e=>e.Y"
                         PointColor="e=> GetPointColor(e)" ShowDataLabels />
    </ApexChart>
</DemoContainer>

@code {
    private List<Order> Orders { get; set; } = SampleData.GetOrders();
    private ApexChartOptions<Order> options { get; set; } = new();

    protected override void OnInitialized()
    {
        options.DataLabels = new DataLabels { DropShadow = new DropShadow { Enabled = false } };
    }


    private string GetPointColor(Order order)
    {
        switch (order.Country)
        {
            case "France":
                return "#e3001b";
            case "Brazil":
                return "#005ba3";
            case "Sweden":
                return "#ffd500";
            case "Spain":
                return "#00783c";
            default:
                return "#87775d";
        }



    }
}